﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using WebApplication6.DAL.DataSetUserTableAdapters;

namespace WebApplication6.manage
{
    public partial class login : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            string username = txtusername.Text;

            string password = txtpassword.Text;


            t_userTableAdapter adapter = new t_userTableAdapter();

            var rows = adapter.GetDataBylogin(username, password,"管理员");

            if (rows.Count <= 0)
            {
                Response.Write("<script language=javascript>alert('登录失败，用户名或密码错误');window.location.href='login.aspx';</script>");
                return;
            }


            var user = rows.Single();

            Session["userrole"] = user.role;
            Session["username"] = user.username;

            Response.Write("<script language=javascript>alert('登录成功');window.location.href='index.aspx';</script>");
        }
    }
}
